package com.ten.mall.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.ten.mall.mapper.YaodianMapper;
import com.ten.mall.service.YaodianService;
import com.ten.mall.vo.Yaodian;
import com.ten.mall.vo.YaodianExample;
import com.ten.mall.vo.YaodianExample.Criteria;
@Service
@Transactional
public class YaodianServiceImpl implements YaodianService {
	@Autowired
	private YaodianMapper yaodianMapper;
	@Override
	@Transactional(readOnly=true)
	public List<Yaodian> selectByPages(Integer start, Integer size, String name) {
		PageHelper.startPage(start, size);
		YaodianExample example =new YaodianExample();
		Criteria c =example.createCriteria();
		if(StringUtils.isNotBlank(name)){
			c.andHouseNameLike("%"+name+"%");
		}
		List<Yaodian> list =yaodianMapper.selectByExample(example);
		return list;
	}

	@Override
	public int insertYaodian(Yaodian record) {
		// TODO Auto-generated method stub
		int i =yaodianMapper.insert(record);
		return i;
	}

	@Override
	public int updateYaodian(Yaodian record) {
		int i =yaodianMapper.updateByPrimaryKeySelective(record);
		return i;
	}

	@Override
	public int deleteYaodoan(Integer id) {
		int i =yaodianMapper.deleteByPrimaryKey(id);
		return i;
	}

	@Override
	@Transactional(readOnly=true)
	public Yaodian selectById(Integer id) {
		Yaodian yaodian =yaodianMapper.selectByPrimaryKey(id);
		return yaodian;
	}

	@Override
	@Transactional(readOnly=true)
	public List<Yaodian> selectAll(String name) {
		YaodianExample example =new YaodianExample();
		Criteria c =example.createCriteria();
		if(StringUtils.isNotBlank(name)){
			c.andHouseNameEqualTo(name);
		}
		List<Yaodian> list =yaodianMapper.selectByExample(example);
		return list;
	}

	@Override
	@Transactional(readOnly=true)
	public List<Yaodian> selectByvo(String weName) {
		YaodianExample example =new YaodianExample();
		Criteria c =example.createCriteria();
		if(StringUtils.isNotBlank(weName)){
			c.andHouseRemarkEqualTo(weName);
		}
		List<Yaodian> list =yaodianMapper.selectByExample(example);
		return list;
	}

	@Override
	@Transactional(readOnly=true)
	public List<Yaodian> selectByKucun(Map<String, String> map) {
		List<Yaodian> list =yaodianMapper.selectByKucun(map);
		return list;
	}

}
